package cn.tips.dmp.supports.jpa;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Date;

/**
 * @author pkb
 */
@Data
@MappedSuperclass
@EntityListeners({AuditingEntityListener.class})
public abstract class BaseJpaSnowflakeIdAndAuditEntity implements Serializable {
    @Id
    @GenericGenerator(
            name = "snowflake-id",
            strategy = "cn.tips.dmp.supports.jpa.SnowflakeIdGenerator"
    )
    @GeneratedValue(
            generator = "snowflake-id"
    )
    @Column(
            name = "id"
    )
    protected Long id;

    @CreatedBy
    @Column(name = "create_by", nullable = false, updatable = false)
    @JsonIgnore
    private String createBy;

    @CreatedDate
    @Column(name = "create_time", nullable = false, updatable = false)
    @JsonIgnore
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime createTime;

    @LastModifiedBy
    @Column(name = "update_by", nullable = false)
    @JsonIgnore
    private String updateBy;

    @LastModifiedDate
    @Column(name = "update_time", nullable = false)
    @JsonIgnore
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime updateTime;

    public BaseJpaSnowflakeIdAndAuditEntity() {
    }

}